home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 17313 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: news.compuserve.com!newsmaster
  2. From: 100435.736@compuserve.com (David A. Mair)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Callback Functions In C++
  5. Date: Mon, 15 Apr 1996 08:18:26 GMT
  6. Organization: CompuServe Incorporated
  7. Message-ID: <4kt0ol$qdt@dub-news-svc-6.compuserve.com>
  8. References: <4kdrfu$kiu@morse.ukonline.co.uk>
  9. NNTP-Posting-Host: hd26-162.compuserve.com
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. andy.walsh@ukonline.co.uk wrote:
  13.  
  14. >Can anyone tell me how I could code a callback function that works
  15. >inside a class and that I can pass the address of to the waveInOpen
  16. >function.  It would seem that a member function carries an extra
  17. >'this' pointer and so cannot be addressed the same as an ordinary
  18. >function.  Any ideas?  I also tried to use Borland's response table
  19. >to handle the messages but it will only respond to a 'SendMessage'
  20. >command and not to my low level audio commands.
  21.  
  22. The response you received from Dmitry covers the most important part
  23. of the method but I thought it would be worth adding something.  If
  24. you use a static member function you will not have a this pointer and
  25. subsequently you will not be able to access any per instance member
  26. variables.  A static member can only make use of other static members
  27. unless it has a way of obtaining the value of this for a particular
  28. instance of the class.  You can do this by creating a static array of
  29. pointers to the class type, although you will need some other
  30. component to ensure that you can find the correct this pointer for the
  31. callback that has happened.  One way might be to maintain a static
  32. array of Window handles with index numbers that match the index
  33. numbers of their associated this pointer for the class to handle the
  34. callback for that window.  This, of course, assumes that the callbacks
  35. are multiple and associated with Windows.
  36.  
  37. Regards
  38. David.
  39.  
  40.